home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’94 / [√] Distribution Restricted! / Christian Ruse / Fourier Paper + Apps / nih-image154_source.sea / V1.54 Source / Text.p < prev    next >
Text File  |  1993-11-17  |  16KB  |  635 lines

  1. unit text;
  2. {This unit contains routines for opening, saving, scrolling and editing text windows.}
  3.  
  4. interface
  5.  
  6.     uses
  7.         QuickDraw, Palettes, PictUtil, PrintTraps, globals, Utilities, Graphics, File2;
  8.  
  9.     procedure UpdateScrollBars;
  10.     procedure UpdateTextWindow (WhichWindow: WindowPtr);
  11.     procedure ActivateTextWindow (WhichWindow: WindowPtr; Activating: boolean);
  12.     procedure DoMouseDownInText (event: EventRecord; WhichWindow: WindowPtr);
  13.     procedure ScrollText;
  14.     procedure GrowTextWindow (NewSize: LongInt);
  15.     function MakeNewTextWindow (name: str255; width, height: integer): boolean;
  16.     function OpenTextFile (name: str255; RefNum: integer): boolean;
  17.     procedure DoKeyDownInText (ch: char);
  18.     procedure ChangeFontOrSize;
  19.     procedure DoTextCopy;
  20.     procedure DoTextPaste;
  21.     procedure DoTextClear;
  22.     procedure SaveText;
  23.     procedure SaveTextAs;
  24.     function SaveTextChanges: integer;
  25.     procedure InsertText (str: str255; EndOfLine: boolean);
  26.     procedure DoFind;
  27.     procedure DecrementTextWindowNums (num: integer);
  28.  
  29.  
  30. implementation
  31.  
  32.  
  33.  
  34.     procedure UpdateScrollBars;
  35.         var
  36.             vMax, vValue, hMax, hValue: integer;
  37.     begin
  38.         with TextInfo^ do begin
  39.                 hlock(handle(TextTE));
  40.                 with TextTE^^, TextTE^^.viewRect do begin
  41.                         vTextPageSize := (bottom - top) div LineHeight;
  42.                         hTextPageSize := right - left;
  43.                         vMax := nLines - vTextPageSize;
  44.                         hMax := 0;
  45.                         vValue := (top - destRect.top) div LineHeight;
  46.                         hValue := left - destRect.left;
  47.                         if vMax < 0 then
  48.                             vMax := 0;
  49.                         if vValue < 0 then
  50.                             vValue := 0;
  51.                         if hMax < 0 then
  52.                             hMax := 0;
  53.                         if vValue < 0 then
  54.                             vValue := 0;
  55.                         SetCtlMax(vTextScrollBar, vMax);
  56.                         SetCtlValue(vTextScrollBar, vValue);
  57.                         SetCtlMax(hTextScrollBar, hMax);
  58.                         SetCtlValue(hTextScrollBar, hValue);
  59.                     end;
  60.                 hunlock(handle(TextTE));
  61.             end;
  62. {ShowMessage(concat('nListColumns= ', Long2str(nListColumns), cr, 'hListPageSize= ', long2str(hListPageSize)));}
  63.     end;
  64.  
  65.  
  66.     procedure SetTextInfo;
  67.   {Updates TextInfo so it points to the active text window.}
  68.         var
  69.             kind: integer;
  70.     begin
  71.         kind := CurrentWindow;
  72.     end;
  73.  
  74.  
  75.     procedure UpdateTextWindow (WhichWindow: WindowPtr);
  76.     begin
  77.         TextInfo := TextInfoPtr(WindowPeek(WhichWindow)^.RefCon);
  78.         if TextInfo <> nil then
  79.             with TextInfo^ do begin
  80.                     SetPort(TextWindowPtr);
  81.                     DrawControls(TextWindowPtr);
  82.                     DrawGrowIcon(TextWindowPtr);
  83.                     EraseRect(TextTE^^.viewRect);
  84.                     TEUpdate(TextTE^^.viewRect, TextTE);
  85.                     UpdateScrollBars;
  86.                 end; {with}
  87.         SetTextInfo;
  88.     end;
  89.  
  90.  
  91.     procedure ActivateTextWindow (WhichWindow: WindowPtr; Activating: boolean);
  92.     begin
  93.         if Activating then
  94.             UpdateTextWindow(WhichWindow);
  95.         TextInfo := TextInfoPtr(WindowPeek(WhichWindow)^.RefCon);
  96.         if TextInfo <> nil then
  97.             with TextInfo^ do
  98.                 if Activating then begin
  99.                         TEActivate(TextTE);
  100.                         ShowControl(hTextScrollBar);
  101.                         ShowControl(vTextScrollBar);
  102.                         WhatToUndo := NothingToUndo;
  103.                     end
  104.                 else begin
  105.                         TEDeactivate(TextTE);
  106.                         HideControl(hTextScrollBar);
  107.                         HideControl(vTextScrollBar);
  108.                     end;
  109.         SetTextInfo;
  110.     end;
  111.  
  112.  
  113.     procedure SetFontSize;
  114.         var
  115.             fInfo: FontInfo;
  116.     begin
  117.         with TextInfo^ do begin
  118.                 SetPort(TextWindowPtr);
  119.                 TextFont(CurrentFontID);
  120.                 TextSize(CurrentSize);
  121.                 with TextTE^^, fInfo do begin
  122.                         GetFontInfo(fInfo);
  123.                         TxSize := CurrentSize;
  124.                         LineHeight := ascent + descent + leading;
  125.                         FontAscent := ascent;
  126.                     end;
  127.             end;
  128.     end;
  129.  
  130.  
  131.     procedure InitTextEdit;
  132.         var
  133.             dRect, vRect: rect;
  134.     begin
  135.         with TextInfo^ do begin
  136.                 SetPort(TextWindowPtr);
  137.                 SetRect(vrect, 0, 0, TextWidth - ScrollBarWidth, TextHeight - ScrollBarWidth);
  138.                 drect := vrect;
  139.                 InsetRect(drect, 4, 4);
  140.                 TextTE := TENew(drect, vrect);
  141.                 with TextTE^^ do begin
  142.                         TxFont := CurrentFontID;
  143.                         SetFontSize;
  144.                         crOnly := 1; {do word wrap}
  145.                     end;
  146.                 TESetSelect(0, 0, TextTE);
  147.                 UpdateScrollBars;
  148.                 TEAutoView(true, TextTE); {Enable auto-scrolling}
  149.             end;
  150.     end;
  151.  
  152.  
  153.     procedure ScrollText;
  154.         var
  155.             value: integer;
  156.     begin
  157.         with TextInfo^, TextInfo^.TextTE^^ do
  158.             TEScroll(0, (viewRect.top - destRect.top) - (GetCtlValue(vTextScrollBar) * LineHeight), TextTE);
  159.     end;
  160.  
  161.  
  162.     procedure ScrAction (theCtl: ControlHandle; partCode: integer);
  163.         var
  164.             bInc, pInc, delta: integer;
  165.     begin
  166.         if TextInfo <> nil then
  167.             with TextInfo^ do begin
  168.                     if theCtl = vTextScrollBar then begin
  169.                             bInc := 1;
  170.                             pInc := vTextPageSize
  171.                         end
  172.                     else begin
  173.                             bInc := 4;
  174.                             pInc := hTextPageSize
  175.                         end;
  176.                     case partCode of
  177.                         inUpButton: 
  178.                             delta := -bInc;
  179.                         inDownButton: 
  180.                             delta := bInc;
  181.                         inPageUp: 
  182.                             delta := -pInc;
  183.                         inPageDown: 
  184.                             delta := pInc;
  185.                         otherwise
  186.                             exit(ScrAction);
  187.                     end;
  188.                     SetCtlValue(theCtl, GetCtlValue(theCtl) + delta);
  189.                     ScrollText;
  190.                 end; {with}
  191.     end;
  192.  
  193.  
  194.     procedure DoMouseDownInText (event: EventRecord; WhichWindow: WindowPtr);
  195.         var
  196.             theCtl: ControlHandle;
  197.             cValue: integer;
  198.             loc: point;
  199.     begin
  200.         TextInfo := TextInfoPtr(WindowPeek(WhichWindow)^.RefCon);
  201.         if TextInfo = nil then
  202.             exit(DoMouseDownInText);
  203.         SelectWindow(WhichWindow);
  204.         SetPort(WhichWindow);
  205.         loc := event.where;
  206.         GlobalToLocal(loc);
  207.         with TextInfo^ do
  208.             if PtInRect(loc, TextTE^^.viewRect) then begin
  209.                     TEClick(loc, BitTst(@event.modifiers, 6), TextTE);
  210.                     UpdateScrollBars;
  211.                 end
  212.             else
  213.                 case FindControl(loc, WhichWindow, theCtl) of
  214.                     inUpButton, inDownButton, inPageUp, inPageDown: 
  215.                         if TrackControl(theCtl, loc, @ScrAction) <> 0 then
  216.                             ;
  217.                     inThumb: 
  218.                         if TrackControl(theCtl, loc, nil) <> 0 then
  219.                             ScrollText;
  220.                     otherwise
  221.                 end;
  222.     end;
  223.  
  224.  
  225.     procedure GrowTextWindow (NewSize: LongInt);
  226.     begin
  227.         if TextInfo <> nil then
  228.             with TextInfo^ do begin
  229.                     TextWidth := LoWord(NewSize);
  230.                     TextHeight := hiWord(NewSize);
  231.                     SetPort(TextWindowPtr);
  232.                     SizeWindow(TextWindowPtr, TextWidth, TextHeight, true);
  233.                     EraseRect(TextWindowPtr^.PortRect);
  234.                     MoveControl(hTextScrollBar, -1, TextHeight - ScrollBarWidth);
  235.                     MoveControl(vTextScrollBar, TextWidth - ScrollBarWidth, -1);
  236.                     SizeControl(hTextScrollBar, TextWidth - 13, ScrollBarWidth + 1);
  237.                     SizeControl(vTextScrollBar, ScrollBarWidth + 1, TextHeight - 13);
  238.                     InvalRect(TextWindowPtr^.PortRect);
  239.                     with TextTE^^ do begin
  240.                             SetRect(viewRect, 0, 0, TextWidth - ScrollBarWidth, TextHeight - ScrollBarWidth);
  241.                             viewRect.bottom := (viewRect.bottom div lineHeight) * lineHeight;
  242.                             destRect := viewRect;
  243.                             InsetRect(destRect, 4, 4);
  244.                         end;
  245.                     TECalText(TextTE);
  246.                     ScrollText;
  247.                 end; {with}
  248.     end;
  249.  
  250.  
  251.     function MakeNewTextWindow (name: str255; width, height: integer): boolean;
  252.         var
  253.             wrect, crect: rect;
  254.     begin
  255.         MakeNewTextWindow := false;
  256.         if nTextWindows >= 10 then begin
  257.                 PutMessage(concat('Image cannot open more than ', long2str(MaxTextWindows), ' text windows.'));
  258.                 exit(MakeNewTextWindow);
  259.             end;
  260.         TextInfo := TextInfoPtr(NewPtr(SizeOf(TextInfoRec)));
  261.         if TextInfo = nil then
  262.             exit(MakeNewTextWindow);
  263.         with TextInfo^ do begin
  264.                 TextWidth := width;
  265.                 TextHeight := height;
  266.                 TextLeft := PicLeft;
  267.                 TextTop := PicTop;
  268.                 PicLeft := PicLeft + hPicOffset;
  269.                 PicTop := PicTop + vPicOffset;
  270.                 if ((PicLeft + TextWidth) > ScreenWidth) or ((PicTop + TextHeight) > ScreenHeight) then begin
  271.                         PicLeft := PicLeftBase;
  272.                         PicTop := PicTopBase;
  273.                     end;
  274.                 SetRect(wrect, TextLeft, TextTop, TextLeft + TextWidth, TextTop + TextHeight);
  275.                 TextWindowPtr := NewWindow(nil, wrect, name, true, 0, pointer(-1), true, 0);
  276.                 if TextWindowPtr = nil then begin
  277.                         DisposPtr(ptr(TextInfo));
  278.                         TextInfo := nil;
  279.                         exit(MakeNewTextWindow);
  280.                     end;
  281.                 WindowPeek(TextWindowPtr)^.WindowKind := TextKind;
  282.                 WindowPeek(TextWindowPtr)^.RefCon := LongInt(TextInfo);
  283.                 SetRect(crect, TextWidth - ScrollBarWidth, -1, TextWidth + 1, TextHeight - 14);
  284.                 vTextScrollBar := NewControl(TextWindowPtr, crect, '', true, 0, 0, TextHeight - 14, ScrollBarProc, 0);
  285.                 SetRect(crect, -1, TextHeight - ScrollBarWidth, TextWidth - 14, TextHeight + 1);
  286.                 hTextScrollBar := NewControl(TextWindowPtr, crect, '', true, 0, 0, TextWidth - 14, ScrollBarProc, 0);
  287.                 InitTextEdit;
  288.                 DrawControls(TextWindowPtr);
  289.                 WhatToUndo := NothingToUndo;
  290.                 TextTitle := name;
  291.                 TextRefNum := 0;
  292.                 Changes := false;
  293.                 TooBig := false;
  294.                 InsMenuItem(WindowsMenuH, 'Dummy', WindowsMenuItems - 1 + nTextWindows);
  295.                 SetItem(WindowsMenuH, WindowsMenuItems + nTextWindows, name);
  296.                 nTextWindows := nTextWindows + 1;
  297.                 WindowNum := nTextWindows;
  298.                 TextWindow[nTextWindows] := TextWindowPtr;
  299.                 MakeNewTextWindow := true;
  300.             end; {with}
  301.     end;
  302.  
  303.  
  304.     function OpenTextFile (name: str255; RefNum: integer): boolean;
  305.         var
  306.             err: OSErr;
  307.             f, item: integer;
  308.             TextFileSize: LongInt;
  309.             LargerThan32K: boolean;
  310.     begin
  311.         OpenTextFile := false;
  312.         if FreeMem < MinFree then begin
  313.                 err := fsclose(f);
  314.                 PutMessage('Not enough memory to open this text file.');
  315.                 exit(OpenTextFile);
  316.             end;
  317.         LargerThan32K := false;
  318.         err := FSOpen(name, RefNum, f);
  319.         err := GetEof(f, TextFileSize);
  320.         if TextFileSize > MaxTextBufSize then begin
  321.                 item := PutMessageWithCancel('This text file is larger than 32K. Would you like to to open the first 32K?');
  322.                 if item = cancel then begin
  323.                         err := fsclose(f);
  324.                         exit(OpenTextFile);
  325.                     end
  326.                 else begin
  327.                         TextFileSize := 30000;
  328.                         LargerThan32K := true;
  329.                     end;
  330.             end;
  331.         if not MakeNewTextWindow(name, 500, 400) then begin
  332.                 err := fsclose(f);
  333.                 exit(OpenTextFile);
  334.             end;
  335.         with TextInfo^ do begin
  336.                 SetHandleSize(TextTE^^.hText, TextFileSize);
  337.                 if MemError <> noErr then begin
  338.                         err := fsclose(f);
  339.                         PutMessage('Out of memory.');
  340.                         DisposePtr(ptr(TextInfo));
  341.                         TextInfo := nil;
  342.                         exit(OpenTextFile);
  343.                     end;
  344.                 err := SetFPos(f, fsFromStart, 0);
  345.                 ShowWatch;
  346.                 TextTE^^.teLength := TextFileSize;
  347.                 err := fsRead(f, TextFileSize, TextTE^^.hText^);
  348.                 if err <> noErr then begin
  349.                         TextTE^^.teLength := 0;
  350.                         SetHandleSize(TextTE^^.hText, 0);
  351.                         err := fsclose(f);
  352.                         exit(OpenTextFile);
  353.                     end;
  354.                 TECalText(TextTE);
  355.                 TextTitle := name;
  356.                 TextRefNum := RefNum;
  357.                 TooBig := LargerThan32K;
  358.             end; {with}
  359.         err := fsclose(f);
  360.         OpenTextFile := true;
  361.     end;
  362.  
  363.  
  364.     procedure DoKeyDownInText (ch: char);
  365.     begin
  366.         if TextInfo <> nil then begin
  367.                 TEKey(ch, TextInfo^.TextTE);
  368.                 TextInfo^.Changes := true;
  369.                 UpdateScrollBars;
  370. {with TextInfo^ do ShowMessage(concat(long2str(TextTE^^.teLength), '  ', long2str(GetHandleSize(TextTE^^.hText))));}
  371.                 WhatToUndo := NothingToUndo;
  372.             end;
  373.     end;
  374.  
  375.  
  376.     procedure ChangeFontOrSize;
  377.     begin
  378.         if TextInfo <> nil then
  379.             with TextInfo^ do begin
  380.                     TextTE^^.TxFont := CurrentFontID;
  381.                     SetFontSize;
  382.                     SetPort(TextWindowPtr);
  383.                     EraseRect(TextTE^^.viewRect);
  384.                     TEUpdate(TextTE^^.viewRect, TextTE);
  385.                     UpdateScrollBars;
  386.                 end; {with}
  387.     end;
  388.  
  389.  
  390.     procedure DoTextCopy;
  391.         var
  392.             err: OSErr;
  393.     begin
  394.         if TextInfo <> nil then begin
  395.                 TECopy(TextInfo^.TextTE);
  396.                 err := ZeroScrap;
  397.                 if err = NoErr then begin
  398.                         err := TEToScrap;
  399.                         WhatsOnClip := NothingOnClip; {It is on System Scrap}
  400.                     end;
  401.             end;
  402.     end;
  403.  
  404.  
  405.     procedure DoTextPaste;
  406.         var
  407.             err: OSErr;
  408.     begin
  409.         if TextInfo <> nil then begin
  410.                 err := TEFromScrap;
  411.                 if err = NoErr then
  412.                     TEPaste(TextInfo^.TextTE);
  413.                 TextInfo^.Changes := true;
  414.                 UpdateScrollBars;
  415.                 WhatToUndo := NothingToUndo;
  416.             end;
  417.     end;
  418.  
  419.  
  420.     procedure DoTextClear;
  421.         var
  422.             err: OSErr;
  423.     begin
  424.         if TextInfo <> nil then begin
  425.                 TEDelete(TextInfo^.TextTE);
  426.                 TextInfo^.Changes := true;
  427.             end;
  428.         UpdateScrollBars;
  429.         WhatToUndo := NothingToUndo;
  430.     end;
  431.  
  432.  
  433.     procedure DoSaveText;
  434.         var
  435.             err, f: integer;
  436.             TheInfo: FInfo;
  437.             ByteCount: LongInt;
  438.     begin
  439.         if TextInfo <> nil then
  440.             with TextInfo^ do begin
  441.                     hlock(handle(TextTE));
  442.                     with TextTE^^ do begin
  443.                             ByteCount := TELength;
  444.                             if ByteCount = 0 then
  445.                                 exit(DoSaveText);
  446.                             err := GetFInfo(TextTitle, TextRefNum, TheInfo);
  447.                             case err of
  448.                                 NoErr: 
  449.                                     if TheInfo.fdType <> 'TEXT' then begin
  450.                                             TypeMismatch(TextTitle);
  451.                                             exit(DoSaveText)
  452.                                         end;
  453.                                 FNFerr:  begin
  454.                                         err := create(TextTitle, TextRefNum, 'Imag', 'TEXT');
  455.                                         if CheckIO(err) <> 0 then
  456.                                             exit(DoSaveText);
  457.                                     end;
  458.                                 otherwise
  459.                                     if CheckIO(err) <> 0 then
  460.                                         exit(DoSaveText)
  461.                             end;
  462.                             ShowWatch;
  463.                             err := fsopen(TextTitle, TextRefNum, f);
  464.                             if CheckIO(err) <> 0 then
  465.                                 exit(DoSaveText);
  466.                             err := fswrite(f, ByteCount, hText^);
  467.                             if CheckIO(err) <> 0 then
  468.                                 exit(DoSaveText);
  469.                             err := SetEof(f, ByteCount);
  470.                             err := fsclose(f);
  471.                             err := FlushVol(nil, TextRefNum);
  472.                             Changes := false;
  473.                         end; {with}
  474.                     hunlock(handle(TextTE));
  475.                 end; {with}
  476.     end;
  477.  
  478.  
  479.     procedure SaveTextAs;
  480.         var
  481.             where: Point;
  482.             reply: SFReply;
  483.     begin
  484.         if TextInfo <> nil then begin
  485.                 where.v := 60;
  486.                 where.h := 100;
  487.                 SFPutFile(where, 'Save Text as?', TextInfo^.TextTitle, nil, reply);
  488.                 if reply.good then
  489.                     with reply, TextInfo^ do begin
  490.                             TextTitle := fname;
  491.                             TextRefNum := vRefNum;
  492.                             DoSaveText;
  493.                             SetWTitle(TextWindowPtr, TextTitle);
  494.                             SetItem(WindowsMenuH, WindowsMenuItems - 1 + WindowNum, TextTitle);
  495.                         end;
  496.             end;
  497.     end;
  498.  
  499.  
  500.     procedure SaveText;
  501.     begin
  502.         if TextInfo <> nil then begin
  503.                 with TextInfo^ do
  504.                     if (TextRefNum = 0) or TooBig then
  505.                         SaveTextAs
  506.                     else
  507.                         DoSaveText;
  508.             end;
  509.     end;
  510.  
  511.  
  512.     function SaveTextChanges: integer;
  513.         const
  514.             yesID = 1;
  515.             NoID = 2;
  516.             CancelID = 3;
  517.         var
  518.             id: integer;
  519.             reply: SFReply;
  520.     begin
  521.         id := 0;
  522.         with TextInfo^ do
  523.             if changes and not TooBig then begin
  524.                     if macro and (MacroCommand = DisposeC) then begin
  525.                             SaveTextChanges := ok;
  526.                             exit(SaveTextChanges);
  527.                         end;
  528.                     ParamText(TextTitle, '', '', '');
  529.                     InitCursor;
  530.                     id := alert(600, nil);
  531.                     if id = yesID then
  532.                         SaveText;
  533.                 end; {if changes}
  534.         if id = cancelID then
  535.             SaveTextChanges := cancel
  536.         else
  537.             SaveTextChanges := ok;
  538.     end;
  539.  
  540.  
  541.     procedure InsertText (str: str255; EndOfLine: boolean);
  542.         var
  543.             i: integer;
  544.     begin
  545.         if TextInfo <> nil then
  546.             with TextInfo^ do begin
  547.                     if EndOfLine then
  548.                         str := concat(str, cr);
  549.                     for i := 1 to length(str) do
  550.                         TEKey(str[i], TextTE);
  551.                     Changes := true;
  552.                     UpdateScrollBars;
  553.                     WhatToUndo := NothingToUndo;
  554.                 end;
  555.     end;
  556.  
  557.  
  558.     procedure DoFind;
  559.         const
  560.             StringID = 3;
  561.         type
  562.             CharArrayType = packed array[0..32767] of char;
  563.             CharArrayPtr = ^CharArrayType;
  564.         var
  565.             mylog: DialogPtr;
  566.             item: integer;
  567.             i, firstpos, lastpos, pos: integer;
  568.             slength: integer;
  569.             match: boolean;
  570.             data: CharArrayPtr;
  571.             c: char;
  572.             str: str255;
  573.     begin
  574.         if TextInfo = nil then
  575.             exit(DoFind);
  576.         hlock(handle(TextInfo^.TextTE));
  577.         with TextInfo^.TextTE^^ do begin
  578.                 if not OptionKeyWasDown then begin
  579.                         InitCursor;
  580.                         ParamText('What would you like to find?', '', '', '');
  581.                         mylog := GetNewDialog(170, nil, pointer(-1));
  582.                         SetDString(MyLog, StringID, SearchString);
  583.                         SelIText(MyLog, StringID, 0, 32767);
  584.                         OutlineButton(MyLog, ok, 16);
  585.                         repeat
  586.                             ModalDialog(nil, item);
  587.                         until (item = ok) or (item = cancel);
  588.                         if item = cancel then begin
  589.                                 DisposDialog(mylog);
  590.                                 exit(DoFind)
  591.                             end;
  592.                         SearchString := GetDString(MyLog, StringID);
  593.                         DisposDialog(mylog);
  594.                     end;
  595.                 slength := Length(SearchString);
  596.                 if slength = 0 then
  597.                     exit(DoFind);
  598.                 str := SearchString;
  599.                 MakeLowerCase(str);
  600.                 data := CharArrayPtr(htext^);
  601.                 match := false;
  602.                 lastpos := teLength - slength - 1;
  603.                 match := false;
  604.                 for firstpos := selEnd to lastpos do begin
  605.                         match := true;
  606.                         for i := 1 to slength do begin
  607.                                 c := data^[firstpos + i - 1];
  608.                                 if (c >= 'A') and (c <= 'Z') then
  609.                                     c := chr(ord(c) + 32);
  610.                                 if c <> str[i] then begin
  611.                                         match := false;
  612.                                         leave
  613.                                     end;
  614.                             end;
  615.                         if match then begin
  616.                                 pos := firstpos;
  617.                                 leave;
  618.                             end;
  619.                     end;
  620.                 if match then begin
  621.                         TESetSelect(pos, pos, TextInfo^.TextTE);
  622.                         TEKey('x', TextInfo^.TextTE);
  623.                         TEKey(BackSpace, TextInfo^.TextTE);
  624.                         TESetSelect(pos, pos + slength, TextInfo^.TextTE);
  625.                         UpdateScrollBars;
  626.                     end
  627.                 else
  628.                     beep;
  629.             end; {with}
  630.         hunlock(handle(TextInfo^.TextTE));
  631.     end;
  632.  
  633.  
  634.  
  635. end.